const cors = require('cors')
const path = require("path")
const art = require('express-art-template')
const express = require('express')
const session = require('cookie-session')

class AppConfig {
    /**
     *
     * @param app {Object} express object
     */
    constructor(app) {
        app.use(cors())

        let _path = path.join(__dirname + '../' + '../' + '/static')
        app.use('/', express.static(_path));
        setTimeout(()=>console.log(`本地静态资源映射路径为${_path}`),0)

        // app.use(express.json({strict: false}))

        app.use(express.urlencoded({extended: true}))

        //express已经继承了这其中的好多中间件 像bodyparser

        app.use(session({httpOnly: true, keys: ['i', 'am', 'sb'], signed: true, maxAge: 1000 * 60}))

        //模板引擎 art-template
        app.engine('html', art)
        app.set('views', path.join(__dirname, '../views'))
        app.set('views engine', 'html')
    }
}


module.exports = AppConfig
